home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / PowerPlant / LDynamicPopupMenu / PopupMenuTester.cp < prev    next >
Encoding:
Text File  |  1995-01-08  |  3.9 KB  |  170 lines  |  [TEXT/CWIE]

  1. //    PopupMenuTest.cp
  2. //        written by Constantine Spathis
  3.  
  4. //    App Specific Headers
  5. #include "LDynamicPopupMenu.h"
  6. #include "PopupTester.h"
  7.  
  8. //    PowerPlant Headers
  9. // PowerPlant Specific Headers - The reason for so many is for registering what we
  10. //        use from powerplant
  11. #include <LWindow.h>
  12. #include <LStdControl.h>
  13. #include <UMemoryMgr.h>
  14. #include <UDrawingState.h>
  15. #include <LGrowZone.h>
  16. #include <UScreenPort.h>
  17. #include <URegistrar.h>
  18. #include <UReanimator.h>
  19. #include <PPobClasses.h>
  20. #include <UPowerTools.h>
  21. #include <PP_Messages.h>
  22.  
  23.  
  24. //    ANSI Headers
  25. #include <stdio.h>
  26.  
  27. void
  28. main()
  29. {
  30.     InitializeHeap(4);
  31.     InitializeToolbox();
  32.     new LGrowZone(20000);
  33.  
  34.     PopupMenuTester    theApp;
  35.     
  36.     theApp.Run();
  37. }
  38. //    PopupMenuTester::PopupMenuTester()
  39. //        12/9/94 CS - Only on constructor needed
  40. PopupMenuTester::PopupMenuTester()
  41. {
  42.     // Init screen stuff PP
  43.     UScreenPort::Initialize();
  44.     
  45.     //    Register PowerPlant Classes
  46.     //    Note I do not need everything that's why I don't call RegisterAllPPClasses to
  47.     //    do it for me.
  48.     URegistrar::RegisterAllPPClasses();
  49.  
  50.     // App Classes
  51.     URegistrar::RegisterClass('LDPM', (ClassCreatorFunc) LDynamicPopupMenu::CreateLDynamicPopupMenuStream);
  52. }
  53.         
  54. //    PopupMenuTester::~PopupMenuTester()
  55. //        12/9/94 CS - Typical destructor, not much to do.
  56. PopupMenuTester::~PopupMenuTester()
  57. {
  58.     ;
  59. }
  60.  
  61. // LApplication functions to override.
  62.  
  63. //    Boolean PopupMenuTester::ObeyCommand(
  64. //            CommandT inCommand,
  65. //             void *ioParam = nil)
  66. //        12/9/94 CS - Dispatch command handling return whether command was handled
  67. Boolean
  68. PopupMenuTester::ObeyCommand(
  69.     CommandT inCommand,
  70.     void *ioParam )
  71. {
  72.     Boolean        cmdHandled = true;
  73.  
  74.     switch (inCommand) {
  75.     
  76.         case cmd_New:
  77.             LWindow* pWindow=LWindow::CreateWindow(1000,this);
  78.             LDynamicPopupMenu* pPopupMenu=(LDynamicPopupMenu*)pWindow->FindPaneByID('LDPM');
  79.             MenuHandle    hTmpMenu=pPopupMenu->GetMacMenuH();
  80.             pPopupMenu->AddListener(this);
  81.             for(int i=0;i<10;i++){
  82.                 char str[64];
  83.                 sprintf(str,"Bjarne %d",i);
  84.                 pPopupMenu->AddCMenuItem(str);
  85.             }
  86.             //    You must remember to call this function when you are
  87.             //    done creating the menu items. Note you can then 
  88.             //    modify the items later w/o calling this function.
  89.             pPopupMenu->FinishedCreatingMenu(2);
  90.             break;
  91.         default:
  92.             cmdHandled = LApplication::ObeyCommand(inCommand, ioParam);
  93.             break;
  94.     }
  95.     
  96.     return cmdHandled;
  97. }
  98. //    void PopupMenuTester::FindCommandStatus(CommandT inCommand,
  99. //              Boolean &outEnabled,
  100. //              Boolean &outUsesMark,
  101. //              Char16 &outMark,
  102. //              Str255 outName)
  103. //        12/10/94 CS - Determine if a command is still active, if no one else understands it.
  104. void
  105. PopupMenuTester::FindCommandStatus(CommandT inCommand,
  106.       Boolean &outEnabled,
  107.       Boolean &outUsesMark,
  108.       Char16 &outMark,
  109.       Str255 outName)
  110. {
  111.     outUsesMark = false;
  112.  
  113.     switch (inCommand) {
  114.  
  115.         case cmd_New:
  116.             outEnabled = true;
  117.             break;
  118.         case cmd_Open:
  119.             outEnabled = true;
  120.             break;
  121.         case cmd_PageSetup:
  122.             outEnabled = true;
  123.             break;
  124.         case cmd_Print:
  125.             outEnabled = false;
  126.             break;
  127.         case cmd_Close:
  128.             outEnabled = false;
  129.             break;        
  130.         default:
  131.             LApplication::FindCommandStatus(inCommand, outEnabled,
  132.                                             outUsesMark, outMark, outName);
  133.             break;
  134.     }
  135. }
  136. //    void PopupMenuTester::EventMouseDown(
  137. //            const EventRecord &inMacEvent)
  138. //        12/10/94 CS - Mousedown event dispatching if it not handled by anyone else in the command
  139. //            chain.
  140. void
  141. PopupMenuTester::EventMouseDown(
  142.     const EventRecord &inMacEvent)
  143. {
  144.     WindowPtr    macWindowP;
  145.     
  146.     Int16    thePart = FindWindow(inMacEvent.where, &macWindowP);
  147.     
  148.     switch (thePart) {
  149.         default:
  150.             LApplication::EventMouseDown(inMacEvent);
  151.             break;
  152.     }
  153. }
  154. //    void ListenToMessage(
  155. //            MessageT inMessage,
  156. //            void* ioParam)
  157. //        1/8/95 CS
  158. //            Listen to popupmenu for this window
  159. void
  160. PopupMenuTester::ListenToMessage(
  161.     MessageT inMessage,
  162.     void* ioParam)
  163. {
  164.     LDynamicPopupMenu*    pPopupMenu=(LDynamicPopupMenu*)ioParam;
  165.     //    Ugly, ugly, ugly....
  166.     if (inMessage!=msg_BroadcasterDied){
  167.         pPopupMenu->SetValue(inMessage);
  168.     }
  169. }
  170.